package rmi.client;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

import persistence.Information;
import persistence.rmi.RessourceRemote;

public class RessourceClient {

	private static Properties props;
	static{
		props = new Properties();
		try {
			FileInputStream fis = new FileInputStream("bin/rmi/client/props.properties");
			props.load(fis);
		} catch (FileNotFoundException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
		
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RessourceClient client = new RessourceClient();

	}

	public RessourceClient() {
		Information info = new Information();
		info.setCle("1");
		info.setValue("Samedi");
		int port = Integer.parseInt(props.getProperty("port.rmi"));
		try {
			Registry annuaire = LocateRegistry.getRegistry(port);
			RessourceRemote remote = (RessourceRemote) annuaire.lookup(props.getProperty("url.service"));
			boolean resultat 		= remote.create(info);
			System.out.println("appel RessourceRemote create"+ resultat);
		} catch (RemoteException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	

}
